/**
 * 
 */
package pac1_rgr;

import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Event;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import widgets.ChooseData;
import java.awt.Rectangle;
import widgets.ChooseRandom;
import rnd.Negexp;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import stat.Histo;
import widgets.Diagram;
import widgets.experiments.ExperimentControl;
import widgets.regres.RegresAnaliser;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import pac1_rgr.FactoryForRgrModel;
import process.Dispatcher;
import java.awt.Color;
import stat.DiscretHisto;
import transProcess.TransMonitorView;

import java.awt.Font;
import java.awt.GridBagLayout;
import javax.swing.JRadioButton;
import java.awt.GridBagConstraints;

/**
 * @author Administrator
 * 
 */
public class Main {

	private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
	private JPanel jContentPane = null;
	private JMenuBar jJMenuBar = null;
	private JMenu fileMenu = null;
	private JMenu editMenu = null;
	private JMenu helpMenu = null;
	private JMenuItem exitMenuItem = null;
	private JMenuItem aboutMenuItem = null;
	private JMenuItem cutMenuItem = null;
	private JMenuItem copyMenuItem = null;
	private JMenuItem pasteMenuItem = null;
	private JMenuItem saveMenuItem = null;
	private JDialog aboutDialog = null;  //  @jve:decl-index=0:visual-constraint="20,634"
	private JPanel aboutContentPane = null;
	private JLabel aboutVersionLabel = null;
	private ChooseData chooseDataWorkers = null;
	private ChooseData chooseDataModelTime = null;
	private ChooseRandom chooseRandomCar1 = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel jPanelTest = null;
	private JPanel jPanelStat = null;
	private Diagram diagramQueueCars = null;
	private JButton jButtonStartTest = null;
	private Diagram diagramStat = null;
	private JScrollPane jScrollPane = null;
	private JTextArea jTextArea = null;
	private JButton jButtonStat = null;
	private ChooseRandom chooseRandomWork = null;
	private DiscretHisto discretHisto = null;  //  @jve:decl-index=0:visual-constraint="785,580"
	private ChooseRandom chooseRandomCar2 = null;
	private Diagram diagramTimeWork = null;
	private Histo histo1 = null;  //  @jve:decl-index=0:visual-constraint="801,650"
	private JTextArea jTextArea1 = null;
	private Diagram diagramStat1 = null;
	private JTextArea jTextArea11 = null;
	private JScrollPane jScrollPane1 = null;
	private JPanel jPanel = null;
	private JPanel jPanel1 = null;
	private ExperimentControl experimentControl = null;
	private RegresAnaliser regresAnaliser = null;
	private FactoryForRgrModel factoryForRgrModel1 = null;
	private TransMonitorView transMonitorView = null;
	private Diagram diagram3 = null;
	private JRadioButton jRadioButton = null;
	private JRadioButton jRadioButton1 = null;
	private Diagram diagram4 = null;
	private JRadioButton jRadioButton2 = null;
	private JRadioButton jRadioButton3 = null;

	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setBounds(new Rectangle(0, 0, 751, 612));
			jFrame.setJMenuBar(getJJMenuBar());
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("Application");
		}
		return jFrame;
	}

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getChooseDataWorkers(), null);
			jContentPane.add(getChooseDataModelTime(), null);
			jContentPane.add(getChooseRandomCar1(), null);
			jContentPane.add(getJTabbedPane(), null);
			jContentPane.add(getChooseRandomWork(), null);
			jContentPane.add(getChooseRandomCar2(), null);
		}
		return jContentPane;
	}

	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getFileMenu());
			jJMenuBar.add(getEditMenu());
			jJMenuBar.add(getHelpMenu());
		}
		return jJMenuBar;
	}

	private JMenu getFileMenu() {
		if (fileMenu == null) {
			fileMenu = new JMenu();
			fileMenu.setText("File");
			fileMenu.add(getSaveMenuItem());
			fileMenu.add(getExitMenuItem());
		}
		return fileMenu;
	}

	private JMenu getEditMenu() {
		if (editMenu == null) {
			editMenu = new JMenu();
			editMenu.setText("Edit");
			editMenu.add(getCutMenuItem());
			editMenu.add(getCopyMenuItem());
			editMenu.add(getPasteMenuItem());
		}
		return editMenu;
	}

	private JMenu getHelpMenu() {
		if (helpMenu == null) {
			helpMenu = new JMenu();
			helpMenu.setText("Help");
			helpMenu.add(getAboutMenuItem());
		}
		return helpMenu;
	}

	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem();
			exitMenuItem.setText("Exit");
			exitMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return exitMenuItem;
	}

	private JMenuItem getAboutMenuItem() {
		if (aboutMenuItem == null) {
			aboutMenuItem = new JMenuItem();
			aboutMenuItem.setText("About");
			aboutMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JDialog aboutDialog = getAboutDialog();
					aboutDialog.pack();
					Point loc = getJFrame().getLocation();
					loc.translate(20, 20);
					aboutDialog.setLocation(loc);
					aboutDialog.setVisible(true);
				}
			});
		}
		return aboutMenuItem;
	}

	private JDialog getAboutDialog() {
		if (aboutDialog == null) {
			aboutDialog = new JDialog(getJFrame(), true);
			aboutDialog.setTitle("About");
			aboutDialog.setBounds(new Rectangle(0, 0, 729, 63));
			aboutDialog.setContentPane(getAboutContentPane());
		}
		return aboutDialog;
	}

	private JPanel getAboutContentPane() {
		if (aboutContentPane == null) {
			aboutContentPane = new JPanel();
			aboutContentPane.setLayout(new BorderLayout());
			aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
		}
		return aboutContentPane;
	}

	private JLabel getAboutVersionLabel() {
		if (aboutVersionLabel == null) {
			aboutVersionLabel = new JLabel();
			aboutVersionLabel.setText("РГР з моделювання студентів групи КІ-091 Ю.Ю.Варвинець, Бойко М.А. варіант 6 ");
			aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return aboutVersionLabel;
	}

	private JMenuItem getCutMenuItem() {
		if (cutMenuItem == null) {
			cutMenuItem = new JMenuItem();
			cutMenuItem.setText("Cut");
			cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
					Event.CTRL_MASK, true));
		}
		return cutMenuItem;
	}

	private JMenuItem getCopyMenuItem() {
		if (copyMenuItem == null) {
			copyMenuItem = new JMenuItem();
			copyMenuItem.setText("Copy");
			copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
					Event.CTRL_MASK, true));
		}
		return copyMenuItem;
	}

	private JMenuItem getPasteMenuItem() {
		if (pasteMenuItem == null) {
			pasteMenuItem = new JMenuItem();
			pasteMenuItem.setText("Paste");
			pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
					Event.CTRL_MASK, true));
		}
		return pasteMenuItem;
	}

	private JMenuItem getSaveMenuItem() {
		if (saveMenuItem == null) {
			saveMenuItem = new JMenuItem();
			saveMenuItem.setText("Save");
			saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					Event.CTRL_MASK, true));
		}
		return saveMenuItem;
	}

	protected ChooseData getChooseDataWorkers() {
		if (chooseDataWorkers == null) {
			chooseDataWorkers = new ChooseData();
			chooseDataWorkers.setBounds(new Rectangle(82, 20, 200, 45));
			chooseDataWorkers.setText("5");
			chooseDataWorkers.setTitle("Кiлькiсть бригад");
			chooseDataWorkers.addCaretListener(new javax.swing.event.CaretListener() {
				public void caretUpdate(javax.swing.event.CaretEvent e) {
					if (getJPanelTest().isShowing()) {
						getDiagramTimeWork().setHorizontalMaxText(
								chooseDataModelTime.getText());
						getDiagramQueueCars().setHorizontalMaxText(
								chooseDataModelTime.getText());
					}
				}
			});
		}
		return chooseDataWorkers;
	}

	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(5, 135, 360, 111));
			jScrollPane.setViewportView(getJTextArea1());
		}
		return jScrollPane;
	}
	
	protected Diagram getDiagramStat() {
		if (diagramStat == null) {
			diagramStat = new Diagram();
			diagramStat.setBounds(new Rectangle(5, 10, 360, 121));
			diagramStat.setVerticalMaxText("1");
			diagramStat.setTitleText("Гiстограма");
			diagramStat.setHorizontalMaxText("480");
		}
		return diagramStat;
	}
	
	protected ChooseData getChooseDataModelTime() {
		if (chooseDataModelTime == null) {
			chooseDataModelTime = new ChooseData();
			chooseDataModelTime.setBounds(new Rectangle(81, 90, 200, 45));
			chooseDataModelTime.setText("480");
			chooseDataModelTime.setTitle("Час моделювання");
			chooseDataModelTime
					.addCaretListener(new javax.swing.event.CaretListener() {
						public void caretUpdate(javax.swing.event.CaretEvent e) {
							if (getJPanelTest().isShowing()) {
								getDiagramTimeWork().setHorizontalMaxText(
										chooseDataModelTime.getText());
								getDiagramQueueCars().setHorizontalMaxText(
										chooseDataModelTime.getText());
							}
						}
					});
		}
		return chooseDataModelTime;
	}

	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.setBounds(new Rectangle(360, 5, 375, 544));
			jTabbedPane.setToolTipText("");
			jTabbedPane.setName("");
			jTabbedPane.addTab("Тест моделi", null, getJPanelTest(), null);
			jTabbedPane.addTab("Статистика", null, getJPanelStat(), null);
			jTabbedPane.addTab("Регресивний", null, getJPanel(), null);
			jTabbedPane.addTab("Перехідний", null, getJPanel1(), null);
		}
		return jTabbedPane;
	}

	private JPanel getJPanelTest() {
		if (jPanelTest == null) {
			jPanelTest = new JPanel();
			jPanelTest.setLayout(null);
			jPanelTest.add(getDiagramQueueCars(), null);
			jPanelTest.add(getJButtonStartTest(), null);
		jPanelTest.add(getDiagramTimeWork(), null);
		}
		return jPanelTest;
	}

	private JPanel getJPanelStat() {
		if (jPanelStat == null) {
			jPanelStat = new JPanel();
			jPanelStat.setLayout(null);
			jPanelStat.add(getDiagramStat(), null);
			jPanelStat.add(getJScrollPane(), null);
			jPanelStat.add(getJButtonStat(), null);
			jPanelStat.add(getDiagramStat1(), null);
			jPanelStat.add(getJScrollPane1(), null);
		}
		return jPanelStat;
	}
	
	protected JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
		}
		return jTextArea;
	}
	
	private JButton getJButtonStartTest() {
		if (jButtonStartTest == null) {
			jButtonStartTest = new JButton();
			jButtonStartTest.setBounds(new Rectangle(102, 303, 175, 25));
			jButtonStartTest.setText("Почати тест");
			jButtonStartTest
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							startTest();
						}
					});
		}
		return jButtonStartTest;
	}


	private JButton getJButtonStat() {
		if (jButtonStat == null) {
			jButtonStat = new JButton();
			jButtonStat.setBounds(new Rectangle(94, 489, 175, 25));
			jButtonStat.setText("Почати експеримент");
			jButtonStat.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					startStat();
				}
			});
		}
		return jButtonStat;
	}
	
	protected DiscretHisto getDiscretHisto() {
		if (discretHisto == null) {
			discretHisto = new DiscretHisto();
		}
		return discretHisto;
	}

	protected ChooseRandom getChooseRandomCar1() {
		if (chooseRandomCar1 == null) {
			chooseRandomCar1 = new ChooseRandom();
			chooseRandomCar1.setBounds(new Rectangle(7, 254, 345, 50));
			chooseRandomCar1.setRandom(new Negexp(10));
			chooseRandomCar1
					.setTitle("Закон розподiлу часу мiж прибуттям вантажівок вдень");
		}
		return chooseRandomCar1;
	}
	
	protected ChooseRandom getChooseRandomWork() {
		if (chooseRandomWork == null) {
			chooseRandomWork = new ChooseRandom();
			chooseRandomWork.setBounds(new Rectangle(6, 176, 346, 50));
			chooseRandomWork.setTitle("Закон розподiлу часу розвантаження вантажівки");
			chooseRandomWork.setRandom(new Negexp(50));
		}
		return chooseRandomWork;
	}

	ChooseRandom getChooseRandomCar2() {
		if (chooseRandomCar2 == null) {
			chooseRandomCar2 = new ChooseRandom();
			chooseRandomCar2.setBounds(new Rectangle(6, 333, 349, 57));
			chooseRandomCar2.setRandom(new Negexp(20));
			chooseRandomCar2.setTitle("Закон розподiлу часу мiж прибуттям вантажівок вночі");
		}
		return chooseRandomCar2;
	}

	 public Diagram getDiagramTimeWork() {
		if (diagramTimeWork == null) {
			diagramTimeWork = new Diagram();
			diagramTimeWork.setBounds(new Rectangle(5, 8, 360, 120));
			diagramTimeWork.setFont(new Font("Dialog", Font.PLAIN, 12));
			diagramTimeWork.setPanelBackground(Color.cyan);
			diagramTimeWork.setHorizontalMaxText("480");
			diagramTimeWork.setTitleText("Бригади що працює понаднормово");
			diagramTimeWork.setVerticalMaxText("10");
			diagramTimeWork.setPainterColor(Color.magenta);
			diagramTimeWork.setGridColor(Color.darkGray);
		}
		return diagramTimeWork;
	}
		
	protected Diagram getDiagramQueueCars() {
			if (diagramQueueCars == null) {
				diagramQueueCars = new Diagram();
				diagramQueueCars.setBounds(new Rectangle(5, 133, 360, 120));
				diagramQueueCars.setFont(new Font("Dialog", Font.PLAIN, 12));
				diagramQueueCars.setVerticalMaxText("10");
				diagramQueueCars.setPanelBackground(Color.cyan);
				diagramQueueCars.setPainterColor(Color.magenta);
				diagramQueueCars.setHorizontalMaxText("480");
				diagramQueueCars.setTitleText("Черга вантажівок");
			}
			return diagramQueueCars;
	}

		Histo getHisto1() {
		if (histo1 == null) {
			histo1 = new Histo();
		}
		return histo1;
	}

	private JTextArea getJTextArea1() {
		if (jTextArea1 == null) {
			jTextArea1 = new JTextArea();
		}
		return jTextArea1;
	}

	private Diagram getDiagramStat1() {
		if (diagramStat1 == null) {
			diagramStat1 = new Diagram();
			diagramStat1.setBounds(new Rectangle(7, 248, 358, 120));
			diagramStat1.setTitleText("Гiстограма");
			diagramStat1.setVerticalMaxText("1");
			diagramStat1.setHorizontalMaxText("480");
		}
		return diagramStat1;
	}

	private JTextArea getJTextArea11() {
		if (jTextArea11 == null) {
			jTextArea11 = new JTextArea();
		}
		return jTextArea11;
	}

	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setBounds(new Rectangle(9, 371, 356, 117));
			jScrollPane1.setViewportView(getJTextArea11());
		}
		return jScrollPane1;
	}

	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setName("");
			jPanel.add(getDiagram3(), null);
			jPanel.add(getExperimentControl(), null);
			jPanel.add(getRegresAnaliser(), null);
			jPanel.add(getJRadioButton(), null);
			jPanel.add(getJRadioButton1(), null);
		}
		return jPanel;
	}

	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.add(getDiagram4(), null);
			jPanel1.add(getTransMonitorView(), null);
			jPanel1.add(getJRadioButton2(), null);
			jPanel1.add(getJRadioButton3(), null);
		}
		return jPanel1;
	}

	private Diagram getDiagram3() {
		if (diagram3 == null) {
			diagram3 = new Diagram();
			diagram3.setHorizontalMaxText("24");
			diagram3.setVerticalMaxText("20");
			diagram3.setBounds(new Rectangle(3, 128, 364, 105));
			diagram3.setTitleText("Діаграма");
		}
		return diagram3;
	}

	public JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setBounds(new Rectangle(39, 461, 289, 21));
			jRadioButton.setText("Середнє значення черги автомобілів");
			jRadioButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioButton.isSelected()){
						getDiagram3().clear();
						getDiagram3().setTitleText("Середнє значення черги автомобілів");
						jRadioButton1.setSelected(false);
					}
				}
			});
		}
		return jRadioButton;
	}

	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setBounds(new Rectangle(38, 490, 292, 21));
			jRadioButton1.setText("Час понаднормової роботи бригад");
			jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioButton1.isSelected()){
						getDiagram3().setTitleText("Час понаднормової роботи бригад");
						getDiagram3().clear();
						jRadioButton.setSelected(false);
					}
				}
			});
		}
		return jRadioButton1;
	}

	private Diagram getDiagram4() {
		if (diagram4 == null) {
			diagram4 = new Diagram();
			diagram4.setFont(new Font("Dialog", Font.PLAIN, 12));
			diagram4.setHorizontalMaxText("480");
			diagram4.setTitleText("Діаграма");
			diagram4.setVerticalMaxText("10");
			diagram4.setPainterColor(Color.magenta);
			diagram4.setGridColor(Color.darkGray);
			diagram4.setBounds(new Rectangle(2, 232, 366, 116));
			diagram4.setPanelBackground(Color.cyan);
		}
		return diagram4;
	}

	/**
	 * This method initializes jRadioButton2	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioButton2() {
			if (jRadioButton2 == null) {
				jRadioButton2 = new JRadioButton();
				jRadioButton2.setBounds(new Rectangle(13, 368, 345, 21));
				jRadioButton2.setText("Перехідний процес для зміни черги авто");
				jRadioButton2.setSelected(true);
				jRadioButton2.addItemListener(new java.awt.event.ItemListener() {
					public void itemStateChanged(java.awt.event.ItemEvent e) {
						if (jRadioButton2.isSelected()){
							getDiagram4().clear();
							getDiagram4().setTitleText("Переходной процесс для изменения очереди");
							jRadioButton3.setSelected(false);
						}
					}
				});
			}
			return jRadioButton2;
	}

	private JRadioButton getJRadioButton3() {
			if (jRadioButton3 == null) {
				jRadioButton3 = new JRadioButton();
				jRadioButton3.setBounds(new Rectangle(13, 404, 347, 21));
				jRadioButton3.setText("Переходной процесс времени ожидания пациента");
				jRadioButton3.setVisible(false);
				jRadioButton3.addItemListener(new java.awt.event.ItemListener() {
					public void itemStateChanged(java.awt.event.ItemEvent e) {
						if (jRadioButton3.isSelected()){
							getDiagram4().setTitleText("Переходной процесс");
							getDiagram4().clear();
							jRadioButton2.setSelected(false);
						}
					}
				});
			}
			return jRadioButton3;
	}

	/**
	 * Launches this application
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Main application = new Main();
				application.getJFrame().setVisible(true);
			}
		});
	}
	
	private ExperimentControl getExperimentControl() {
		if (experimentControl == null) {
			experimentControl = new ExperimentControl();
			experimentControl.setTextFactors("3 10 12 16 19");
			experimentControl.setTextNExpr("10");
			experimentControl.setTextTestTime("200");
			experimentControl.setBounds(new Rectangle(2, 6, 379, 118));
			experimentControl.setFactory(getFactoryForRgrModel1());
			experimentControl.setDiagram(getDiagram3());
		}
		return experimentControl;
	}
	
	private FactoryForRgrModel getFactoryForRgrModel1() {
		if (factoryForRgrModel1 == null) {
			factoryForRgrModel1 = new FactoryForRgrModel(this);
		}
		return factoryForRgrModel1;
	}
	
	private RegresAnaliser getRegresAnaliser() {
		if (regresAnaliser == null) {
			regresAnaliser = new RegresAnaliser();
			regresAnaliser.setBounds(new Rectangle(1, 230, 376, 225));
			regresAnaliser.setExperimentControl(getExperimentControl());
			regresAnaliser.setDiagram(getDiagram3());
	
		}
		return regresAnaliser;
	}
	
	private TransMonitorView getTransMonitorView() {
		if (transMonitorView == null) {
			transMonitorView = new TransMonitorView();
			transMonitorView.setИнтервал_усреднения("20");
			transMonitorView.setКоличество_интервалов("30");
			transMonitorView.setПараллельно_моделей("50");
			transMonitorView.setBounds(new Rectangle(100, 7, 164, 212));
			transMonitorView.setFactory(getFactoryForRgrModel1());
			transMonitorView.setDiagram(getDiagram4());
		}
		return transMonitorView;
	}
	
	private void startTest() {
		getDiagramTimeWork().clear();
		getDiagramQueueCars().clear();
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		Model model =(Model) factory.createModel(dispatcher);
		model.initForTest();
		dispatcher.start();
		getJButtonStartTest().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера,
		// а після цього відновлює доступність кнопки "Старт"
		new Thread() {
			public void run() {
				// Затримка до кінця моделювання
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStartTest().setEnabled(true);
			}
		}.start();
	}

	public void startStat() {
		getDiagramStat().clear();
		getJTextArea1().setText("");
		getDiagramStat1().clear();
		getJTextArea11().setText("");
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		final Model model = (Model)factory.createModel(dispatcher);
		model.initForStat();
		dispatcher.start();
		getJButtonStat().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера
		// а після цього відновлює доступність кнопки "Почати експеримент"
		// та виводить на екран статистичні характеристики черги
		new Thread() {
			public void run() {
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStat().setEnabled(true);
				getHisto1().showRelFrec(getDiagramStat());
				getJTextArea1().setText(getHisto1().toString());
				getJTextArea1().select(0, 0);
				getDiscretHisto().showRelFrec(getDiagramStat1());
				getJTextArea11().setText(getDiscretHisto().toString());
				getJTextArea11().select(0, 0);
			}
		}.start();

	}
}  //  @jve:decl-index=0:visual-constraint="804,524"
